﻿#form
from django import forms
from django.forms import CharField
from django.forms.widgets import *
from django.core import validators

from hwcorp.apps.blog.models import *

from django.forms import ModelForm


class PostForm(ModelForm):
    class Meta:
        model = Post
    
class NewPostForm(forms.Form):
    title = forms.CharField(label = "Entry Title", max_length = 255, widget = forms.TextInput(attrs = {'class':'post-title', }))
    content = forms.CharField(label = "Content", required = False, widget = forms.Textarea(attrs = {'class':'post-body'}))
    
    def save(self):
        p = Post(
            title = self.cleaned_data['title'],
            content = self.cleaned_data['content'],
        )
        p.save()
        
class NewCommentForm(forms.Form):
    name = forms.CharField(label = "Name", max_length = 255)
    email = forms.EmailField(label = "Email",)
    content = forms.CharField(label = "Comment", required = False, widget = forms.Textarea(attrs = {'class':'comment-body'}))
    def save(self, post):
        p = Comment(
            name = self.cleaned_data['name'],
            content = self.cleaned_data['content'],
            email = self.cleaned_data['email'],
            post = post,
        )
        p.save()
